<div class="widget">
	<div class="widget-header bg-blue">
		<i class="widget-icon icon-notebook"></i> 
		<span class="widget-caption"> 查看 </span>
		<div class="widget-buttons">
			<a href="javascript:void(0);" onclick="handlerCancel(this);" title="关闭"
				 data-toggle="dispose" data-refresh-table="#table-contract"> <i class="fa fa-times"></i> </a> 
		</div>
	</div>
	<div class="widget-body">
		<!-- TODO 停课信息 -->
		<div class="widget radius-bordered mgbt-xs-10" id="stop">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 停课信息 </span>
			</div>
			<div class="widget-body editor-body-sm editor-body-stopinfo">
			
			</div>
		</div>
		
		<!-- TODO 处理信息 -->
		<div class="widget radius-bordered mgbt-xs-10" id="refund">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 处理信息 </span>
			</div>
			<div class="widget-body editor-body-sm editor-body-refund">
				<form class="form-horizontal form-editor form-editor-refund">
					<div class="row">
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="buying">购买课时</label>
								<div class="col-sm-8">
									<span id="buying" class="form-control readonly"></span>
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="useing">已用课时</label>
								<div class="col-sm-8">
									<span id="useing" class="form-control readonly"></span>
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="rested">剩余课时</label>
								<div class="col-sm-8">
									<span id="rested" class="form-control readonly"></span>
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="totalsPrice">总金额</label>
								<div class="col-sm-8">
									<span id="totalsPrice" class="form-control readonly"></span>
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="useingPrice">已用金额</label>
								<div class="col-sm-8">
									<span id="useingPrice" class="form-control readonly"></span>
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="restedPrice">剩余金额</label>
								<div class="col-sm-8">
									<span id="restedPrice" class="form-control readonly"></span>
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label">处理类型</label>
								<div class="col-sm-8">
									<span id="type" class="form-control readonly"></span>
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="createDate">处理时间</label>
								<div class="col-sm-8">
									<span id="createDate" class="form-control readonly"></span>
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="username">处理人</label>
								<div class="col-sm-8">
									<span id="conductor" class="form-control readonly"></span>
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="reason">终止原因</label>
								<div class="col-sm-8">
									<span id="reason" class="form-control readonly"></span>
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="amount">退费金额</label>
								<div class="col-sm-8">
									<span id="amount" class="form-control readonly"></span>
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="payment">退费方式</label>
								<div class="col-sm-8">
									<span id="payment" class="form-control readonly"></span>
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-sm-8">
							<div class="form-group">
								<label class="col-sm-2 control-label" for="remark">备注</label>
								<div class="col-sm-10">
									<span id="remark" class="form-control readonly"></span>
								</div>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		
		<!-- TODO 基本信息 -->
		<div class="widget radius-bordered mgbt-xs-10">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 基本信息 </span>
			</div>
			<div class="widget-body editor-body-sm editor-body-contract">
				
			</div>
		</div>
		
		<!-- TODO 购买信息 -->
		<div class="widget radius-bordered mgbt-xs-10" id="editor-panel-buyinfo">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> <a href="" data-toggle="collapse"> 购买信息 </a> </span>
				<div class="widget-buttons compact">
					<a href="" data-toggle="collapse"> <i class="fa fa-expand"></i> </a> 
				</div>
			</div>
			<div class="widget-body editor-body-sm editor-body-buyinfo">
				
			</div>
		</div>
		
		<!-- TODO 付款信息 -->
		<div class="widget radius-bordered mgbt-xs-10" id="editor-panel-payinfo">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> <a href="" data-toggle="collapse"> 付款信息 </a> </span>
				<div class="widget-buttons compact">
					<a href="" data-toggle="collapse"> <i class="fa fa-expand"></i> </a> 
				</div>
			</div>
			<div class="widget-body editor-body-sm editor-body-payinfo">
				
			</div>
		</div>
		
		<!-- TODO 购买历史 -->
		<div class="widget radius-bordered mgbt-xs-10" id="editor-panel-history">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> <a href="" data-toggle="collapse"> 购买历史 </a> </span>
				<div class="widget-buttons compact">
					<a href="" data-toggle="collapse"> <i class="fa fa-expand"></i> </a> 
				</div>
			</div>
			<div class="widget-body editor-body-sm">
				<table data-ajax="handlerSearch" data-method="post"
							 data-id-field="id" 
							 data-unique-id="id" 
							 data-pagination="true"  
							 data-check-on-init="true" 
							 data-side-pagination="server" 
							 data-mobile-responsive="true"
							 data-form-search="#search-form-history" id="table-history">
					<thead>
						<tr>
							<th data-checkbox="true"></th>
							<th data-field="student" 		data-align="center">宝宝姓名</th>
							<th data-field="item" 			data-align="center">购买项目</th>
							<th data-field="type" 			data-align="center">项目类型</th>
							<th data-field="createDate" data-align="center">购买时间</th>
							<th data-field="fromDate" 	data-align="center">起止时间</th>
							<th data-field="totals" 		data-align="center">总金额</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
		
	</div>
</div>

<!-- 提交表单 ========================================================= -->
<form id="editor-form-stopinfo" action="/miwawa/{dbname}/common/save" method="post" 
			name="com.app.miwawa.api.esm.entity.contract.Stopinfo">
			<input type="hidden" name="bean['status']" value="0">
			<input type="hidden" name="bean['invalid']" value="F">
			<input type="hidden" name="bean['contractId']" data-foreign-id>
</form>

<!-- 查询表单 ========================================================= -->
<form id="search-form-stopinfo" action="/miwawa/{dbname}/common/search.json" method="post" 
			name="com.app.miwawa.api.esm.entity.contract.Stopinfo" 
			data-template-target=".editor-body-stopinfo" data-template-id="#view-pause-template" 
			data-template-path="/miwawa/content/esm/contract/template.html">
			<input type="hidden" name="invalid" value="F" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="contractId" id="contractId" data-search-group="and" data-search-operation="EQ">
</form>

<script type="text/javascript">
<!--
	require(['domReady'],function(domReady){
		domReady(function () {
			jQuery("#search-form-buyinfo").data("template-id","#view-buyinfo-template");
			jQuery("#search-form-payinfo").data("template-id","#view-payinfo-template");
			
			initData();
		});
	});
	
	var contract;
	function initData(){
		contract = jQuery("#table-contract").data("selectedRow");

		jQuery("#userid",".form-editor-stopinfo").val(userid);
		jQuery("#username",".form-editor-stopinfo").val(username);
		jQuery(":hidden[name='contractId'],[data-foreign-id]").val(contract.id);
		jQuery(":hidden[name='studentid']").val(contract.studentid);
		jQuery("#contractId","#search-form-stopinfo").val(contract.id);
		
		if(contract.status == "refund" || contract.status == "finish"){
			jQuery("#stop").hide();
			getRefund();
		}else if(contract.status == "pause"){
			jQuery("#refund").hide();
		}else{
			jQuery("#stop").hide();
			jQuery("#refund").hide();
		}
		
		jQuery(".editor-body-contract").loadform("load", {
			templateId: "#view-contract-template",
			templatePath: "/miwawa/content/esm/contract/template.html",
			templateData: contract
		});
		
		jQuery("#search-form-stopinfo").loadform("many");
		
		jQuery("#search-form-buyinfo").loadform("many",helperBuyinfo());
		
	 	jQuery("#search-form-payinfo").loadform("many");
	 	
		jQuery("#table-history").bootstrapTable({
			onLoadSuccess:function(data){
				require(['jquery.plugin.form'],function(form){
					form.datepicker(".date-selector");
					form.tooltip("[data-toggle='tooltip']");
				});
			}
		});
	}
	
	function getRefund(){
		
		jQuery.ajaxsend({
			url:"/miwawa/{dbname}/common/search.json".replace("{dbname}",dbname),
			data:{
				"entityClass" : "com.app.miwawa.api.esm.entity.contract.Refund",
	     	"and[0][operator]": "EQ",
	    	"and[0][fieldName]": "contractId",					
	    	"and[0][fieldValue]": contract.id
			},
			success:function(data){
				var refund = data.rows;
				jQuery("#buying",".form-editor-refund").text(contract.buying);
				jQuery("#useing",".form-editor-refund").text(contract.useing);
				jQuery("#rested",".form-editor-refund").text(contract.rested);
				jQuery("#totalsPrice",".form-editor-refund").text(contract.totalsPrice);
				jQuery("#useingPrice",".form-editor-refund").text(contract.useingPrice);
				jQuery("#restedPrice",".form-editor-refund").text(contract.restedPrice);
				jQuery("#type").text(refund[0].type);
				jQuery("#createDate").text(refund[0].createDate);
				jQuery("#conductor").text(refund[0].username);
				jQuery("#reason").text(refund[0].reason);
				jQuery("#amount").text(refund[0].amount);
				jQuery("#payment").text(refund[0].payment);
				jQuery("#remark").text(refund[0].remark);
			}
		})
	}
	
//-->
</script>